<html>
<head><meta charset="utf-8"><title>LSP: Difference between Goto Definition and Goto Declaration · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/LSP.3A.20Difference.20between.20Goto.20Definition.20and.20Goto.20Declaration.html">LSP: Difference between Goto Definition and Goto Declaration</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="233199055"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/LSP%3A%20Difference%20between%20Goto%20Definition%20and%20Goto%20Declaration/near/233199055" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Viliam Vadocz <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/LSP.3A.20Difference.20between.20Goto.20Definition.20and.20Goto.20Declaration.html#233199055">(Apr 05 2021 at 16:59)</a>:</h4>
<p>What is the difference between Goto Declaration and Goto Definition in the Language Server Protocol?<br>
Goto Definition: <a href="https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_definition">https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_definition</a><br>
Goto Declaration: <a href="https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_declaration">https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_declaration</a></p>
<p>Should a language server implement both or only one?<br>
(Sorry about cross-posting to #t-compiler/help, I didn't know where to ask.)</p>



<a name="233199321"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/LSP%3A%20Difference%20between%20Goto%20Definition%20and%20Goto%20Declaration/near/233199321" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Viliam Vadocz <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/LSP.3A.20Difference.20between.20Goto.20Definition.20and.20Goto.20Declaration.html#233199321">(Apr 05 2021 at 17:01)</a>:</h4>
<p>After looking at the rust-analyzer source, it seems only Goto definition is implemented. Is Goto Declaration an older name kept for backwards compatibility?</p>



<a name="233199327"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/LSP%3A%20Difference%20between%20Goto%20Definition%20and%20Goto%20Declaration/near/233199327" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremy Kolb <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/LSP.3A.20Difference.20between.20Goto.20Definition.20and.20Goto.20Declaration.html#233199327">(Apr 05 2021 at 17:01)</a>:</h4>
<p>It's really used in languages that need the distinction between declaration and well... definition. For instance in C++ you can have a variable declared somewhere (ex a header) and defined somewhere else (cpp)</p>



<a name="233199486"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/LSP%3A%20Difference%20between%20Goto%20Definition%20and%20Goto%20Declaration/near/233199486" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Viliam Vadocz <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/LSP.3A.20Difference.20between.20Goto.20Definition.20and.20Goto.20Declaration.html#233199486">(Apr 05 2021 at 17:02)</a>:</h4>
<p>Ok, that makes sense. Thanks.</p>



<a name="233199543"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/LSP%3A%20Difference%20between%20Goto%20Definition%20and%20Goto%20Declaration/near/233199543" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremy Kolb <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/LSP.3A.20Difference.20between.20Goto.20Definition.20and.20Goto.20Declaration.html#233199543">(Apr 05 2021 at 17:02)</a>:</h4>
<p>We don't use it in <code>rust-analyzer</code>: <a href="https://github.com/rust-analyzer/rust-analyzer/blob/1ae20d2b894171f0b8368309da727cd365b95fc1/crates/rust-analyzer/src/caps.rs#L46">https://github.com/rust-analyzer/rust-analyzer/blob/1ae20d2b894171f0b8368309da727cd365b95fc1/crates/rust-analyzer/src/caps.rs#L46</a></p>



<a name="233199643"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/LSP%3A%20Difference%20between%20Goto%20Definition%20and%20Goto%20Declaration/near/233199643" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremy Kolb <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/LSP.3A.20Difference.20between.20Goto.20Definition.20and.20Goto.20Declaration.html#233199643">(Apr 05 2021 at 17:03)</a>:</h4>
<p>If you have questions about the LSP protocol itself the best place is: <a href="https://github.com/microsoft/language-server-protocol">https://github.com/microsoft/language-server-protocol</a></p>



<a name="233199826"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/LSP%3A%20Difference%20between%20Goto%20Definition%20and%20Goto%20Declaration/near/233199826" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Viliam Vadocz <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/LSP.3A.20Difference.20between.20Goto.20Definition.20and.20Goto.20Declaration.html#233199826">(Apr 05 2021 at 17:05)</a>:</h4>
<p>That's helpful.<br>
If I have questions about language server implementation is it ok if I ask here? I am using Rust for mine (+ similar dependencies), but it's for a different target language.</p>



<a name="233200126"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/LSP%3A%20Difference%20between%20Goto%20Definition%20and%20Goto%20Declaration/near/233200126" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremy Kolb <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/LSP.3A.20Difference.20between.20Goto.20Definition.20and.20Goto.20Declaration.html#233200126">(Apr 05 2021 at 17:08)</a>:</h4>
<p>I can answer some questions</p>



<a name="233200339"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/LSP%3A%20Difference%20between%20Goto%20Definition%20and%20Goto%20Declaration/near/233200339" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremy Kolb <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/LSP.3A.20Difference.20between.20Goto.20Definition.20and.20Goto.20Declaration.html#233200339">(Apr 05 2021 at 17:09)</a>:</h4>
<p>We use <a href="https://crates.io/crates/lsp_server">https://crates.io/crates/lsp_server</a> and <a href="https://crates.io/crates/lsp_types">https://crates.io/crates/lsp_types</a>. <a href="https://crates.io/crates/tower-lsp">https://crates.io/crates/tower-lsp</a> is also an implementation but I haven't played with it.</p>



<a name="233202325"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/LSP%3A%20Difference%20between%20Goto%20Definition%20and%20Goto%20Declaration/near/233202325" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/LSP.3A.20Difference.20between.20Goto.20Definition.20and.20Goto.20Declaration.html#233202325">(Apr 05 2021 at 17:25)</a>:</h4>
<p>see also <a href="https://github.com/rust-analyzer/rust-analyzer/issues/2541">https://github.com/rust-analyzer/rust-analyzer/issues/2541</a></p>



<a name="233203300"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/LSP%3A%20Difference%20between%20Goto%20Definition%20and%20Goto%20Declaration/near/233203300" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremy Kolb <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/LSP.3A.20Difference.20between.20Goto.20Definition.20and.20Goto.20Declaration.html#233203300">(Apr 05 2021 at 17:33)</a>:</h4>
<p>Good point! I forgot about that issue.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>